#ifndef GY_TREECOMBOBOX_H
#define GY_TREECOMBOBOX_H

#include <QObject>
#include <QComboBox>
#include <QTreeView>
#include <QStandardItemModel>
#include <QLineEdit>
#include <QHeaderView>
#include <QMouseEvent>
#include <QSet>
#include "GY_ControlLibrary_global.h"


///
/// \brief The dataStruct struct
/// 传入和传出的数据格式
///
struct dataStruct{
    QList <QVariant> currRowData;//树中一行数据
    QList <dataStruct> childData;//子节点数据
};
///
/// \brief The GY_TreeComboBox class
/// 继承于QComboBox的类
///
class GY_CONTROLLIBRARY_EXPORT GY_TreeComboBox: public QComboBox
{
    Q_OBJECT
public:
    GY_TreeComboBox();
public:
    ///
    /// \brief setColumnNumber 设置列数，不调用则默认为一列
    /// \param coluNumber 默认为1
    ///
    void setColumnNumber(const int coluNumber = 1);
    ///
    /// \brief addTreeHead 添加树的头，不调用则无头，
    /// \param headList 若不调用setColumnNumber，则以list个数为树的列数
    ///
    void addTreeHead(QList <QString>  &headList);
    ///
    /// \brief addTreeData 向树中添加数据
    /// \param data 树结构
    ///
    void addTreeData(QList <dataStruct> &data,bool isCheck = false);
    ///
    /// \brief getCurrNodeAndChildInfor 获取当前节点及子节点信息
    /// \return 当前节点及子节点信息
    ///
    dataStruct * getCurrNodeAndChildInfor();
    ///
    /// \brief clearAllData 清空所有数据
    ///
    void clearAllData();
    ///
    /// \brief changeTreeHead 修改树的头
    /// \param headList 新的头
    /// \return true:修改成功,false:修改失败
    ///
    bool changeTreeHead(QList <QString>  &headList);
    ///
    /// \brief getCheckItem 获取所有勾选的Item
    /// \return 所有的被勾选的item（不包括半勾选）
    ///
    QList <QStandardItem *> getCheckItem();
    ///
    /// \brief findItemTodata 根据item获取当前行所有数据
    /// \param item 查找依据
    /// \return item对应的一行数据
    ///
    QList <QVariant> findItemTodata(QStandardItem *item);

private:
    ///
    /// \brief addChild 添加子节点
    /// \param item 父节点
    /// \param chaildList 子节点信息
    ///
    void addChild(QStandardItem *item,QList <dataStruct> chaildList);
    ///
    /// \brief getCurrCodePath 获取当前节点路径
    /// \param curritem 当前节点
    /// \param path 返回值，当前节点所在的路径
    ///
    void getCurrCodePath(QStandardItem *curritem,QString &path);
    ///
    /// \brief getCurrNodeItem 获取当前节点下所有子节点
    /// \param currItem 当前节点
    /// \param dataInfor 返回值，当前节点信息
    ///
    void getCurrNodeItem(QStandardItem *currItem, dataStruct *dataInfor);
    ///
    /// \brief checkCurrCodeAndChild 勾选当前节点和子节点
    /// \param currItem 当前节点
    /// \param isCheck 是否勾选
    ///
    void checkCurrCodeAndChild(QStandardItem *currItem,bool isCheck);
    ///
    /// \brief getCheckName 获取所有勾选的名字
    /// \return 名字集合
    ///
    QString getCheckName();
    ///
    /// \brief changeParentCheck 改变父节点的点击状态
    /// \param currItem 当前节点
    ///
    void changeParentCheck(QStandardItem *currItem);



private slots:

    //获取当前点击item
    void getCurrClickItem();
private:
    //数据模型
    QStandardItemModel *m_pTreeMode;
    //树
    QTreeView *m_pTreeView;
    //当前点击节点
    QStandardItem *m_pCurrItem;
    //数据内容
    QList <dataStruct> m_data;
    //item对应一整行数据
    QMap <QStandardItem *,QList <QVariant>> m_itemToData;
    //允许收缩标志
    bool m_canPopup;
    //是否复选
    bool m_isCheck;
    //是否点击了item
    bool m_isCheckItem;

    // QComboBox interface
public:
    void hidePopup();
};

#endif // GY_TREECOMBOBOX_H
